using FSM.IBll; 
using FSM.Model; 
using FSM.Web.Models; 
using FSM.Web.Models.Fileter; 
using Microsoft.AspNetCore.Mvc; 
using System; 
using System.Collections.Generic;
using System.IO;
using System.Linq; 
using System.Threading.Tasks; 
 
namespace FSM.Web.Controllers 
{ 
    public class LogEventController : BaseController 
    { 
        #region 模块 
 
        private readonly DataResultModel drm; 
 
        private readonly ILogEventBll _bll; 
 
        #endregion 
 
        #region 构造函数 
 
        public LogEventController(ILogEventBll bll) 
        { 
            _bll = bll; 
            drm = new DataResultModel(); 
            ModuleNo = "0108"; 
        } 
 
        #endregion 
 
        #region 功能 
 
        public IActionResult Index() 
        { 
            return View(); 
        } 
 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0108", "Query")] 
        public JsonResult Get(int id) 
        { 
            log_event model = _bll.Get(id); 
            drm.success = true; 
            drm.data = model; 
            return drm.ToJson(); 
        } 
 
        /// <summary> 
        /// 查询 
        /// </summary> 
        /// <param name="eventId">事件id</param> 
        /// <param name="message">消息</param> 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0108", "Query")] 
        public JsonResult List(int? eventId, string message, int? page = 1, int? page_size = 30) 
        { 
            Tuple<List<log_event>, int> result = _bll.ListPagin(eventId, message, page.Value, page_size.Value); 
            drm.success = true; 
            drm.data = result.Item1; 
            drm.total = result.Item2; 
            return new JsonResult(drm); 
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [OperateAuthorize("0108", "Export")]
        public FileResult Export(int? eventId, string message)
        {
            byte[] bytes = _bll.Export(eventId, message);
            return File(bytes, "application/octet-stream", $"日志{DateTime.Now:yyyyMMddHHmmss}.xlsx");
        }

        #endregion 
    } 
} 
